﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



namespace Forging2.Common.Forging
{
    public class ForgingData
    {


        public ForgingData()
        {
            // UpdatDBConString();

        }
        /*
        public struct PLCParameter
        {
            public int BaseValue;
            public int WorktableHeight;
            public int SettingHeight;
        }

        
        /// <summary>
        /// MES派工单信息
        /// </summary>
        public struct JobNo
        {
            string GID;
            string DISPATCH_CODE;
            string PRODU_CODE;
            string PRODU_NAME;
            string ORDER_GID;

        }

        /// <summary>
        /// 锻压记录
        /// </summary>
        public struct WorkRecord
        {
            string WorkRecord_id;
            string ForgeNo;
            string ForgeName;
            Byte RecordType;
            string JobNo;
            Byte LayerCount;
            string Icmo_id;
            string Route_id;
            string WorkCellNo;
            Byte CombineMethod;
            string WorkRecordDetail_id;
            int SequenceNo;
            string Parameter_id;
            DateTime WorkpieceTime;
            int WorkpieceHeight;
            int TemperatureValue;
            Byte HeatCount;
            Byte IsDelete;
            Byte State;
        }
        */
        //public JobNo CurJob { set; get; }

        //public DataBase.ZH_IMES.task_view CurrentTask_View { private set; get; }


        /// <summary>
        /// 当前派工单号
        /// </summary>
        //public DataBase.ZH_IMES.uex_vtrack_record CurrentJobNo { private set; get; }
        public DataBase.ZH_IMES.V_ForgingOperateData CurrentJobNo { get; private set; }
        public DataBase.QID_IGDATA_ZY.dy_plan_icmo CurrentIcmo { private set; get; }
        public DataBase.QID_IGDATA_ZY.dy_route_line CurrentRoute { private set; get; }
        public DataBase.QID_IGDATA_ZY.dy_plc_parameter CurrentParameter { private set; get; }
        public DataBase.QID_IGDATA_ZY.dy_workrecord_detail CurrrentWorkrecordDetail { private set; get; }
        //public List<DataBase.QID_IGDATA_ZY.V_WorkRecord> CurrentWorkRecord { set; get; }

        public string CurrentForgeNo { get; set; }
        public bool IsWorking { set; get; } = false;
        public string CurrentWorkRecord_id { private set; get; }
        public string CurrentWorkRecordDetail_id { private set; get; }
        public int CurrentSeq { private set; get; }
        public string CurrentLEDString { private set; get; }

        public List<DataBase.ZH_IMES.V_ForgingOperateData> InFurnaceData;
        public List<DataBase.ZH_IMES.V_ForgingOperateData> OutFurnaceData;
        //public List<DataBase.ZH_IMES.V_ForgingOperateData> OperateData;

        //public Thread RealTimeQuery;

        public bool IsChanged = false;

        //public System.Data.Entity.DbSet<DataBase.ZH_IMES.task_view> CurrentTaskView { private set; get; }


        //public DataBase.ZH_IMES.v_JRL_DY1 CurrentTask_View { get; private set; }

        public enum SaveDataType
        {
            dy = 1,
            zh = 2,
            mes = 3
        }

        /*
        private bool isRealQuery = false;
        private EventHandler RealTimeHandler;
        */



        public void DataInit(string gid)
        {
            if (Const.IGDataDbContext.dy_plan_icmo.Count() == 0)
            {
                var dr = new DataBase.QID_IGDATA_ZY.dy_plan_icmo();
                dr.Icmo_id = "icmoid";
                dr.IsDelete = 0;
                dr.State = 0;
                dr.BillNo = "0";
                dr.CombineMethod = 1;
                dr.Name = "未指定材质";
                dr.Specification = "未指定规格";
                dr.QTY = 9999;
                Const.IGDataDbContext.dy_plan_icmo.Add(dr);


            }
            if (Const.IGDataDbContext.dy_route_line.Count() == 0)
            {
                var dr = new DataBase.QID_IGDATA_ZY.dy_route_line();
                dr.Route_id = "routeid";
                dr.IsDelete = 0;
                dr.State = 0;
                dr.RouteName = "未指定工艺路线名称";
                dr.ForgeNo = "未指定锻件编号";


            }
            if (Const.IGDataDbContext.dy_plc_parameter.Count() == 0)
            {
                var dr = new DataBase.QID_IGDATA_ZY.dy_plc_parameter();
                dr.Parameter_id = "parameterid";
                dr.IsDelete = 0;
                dr.State = 0;
                dr.BaseValue = 4500;
                dr.SettingHeight = 0;
                dr.CreateDate = DateTime.Now;
            }
            //DataBase.SaveChanges();
            DataSave(SaveDataType.dy);
            /* 在前台实现LED屏显示
            var r = Const.ZH_IMESDbContext.uex_vtrack_record.Find(gid);

            return;
            CurrentIcmo = Const.IGDataDbContext.dy_plan_icmo.Find(r.ORDER_GID);
            CurrentRoute = Const.IGDataDbContext.dy_route_line.Find(r.ROUTE_GID);
            CurrentJobNo = Const.v_ForgingOperateDatas.Find(v => v.GID == gid);
            if (CurrentJobNo == null)
            {
                IsWorking = false;
            }
            else
            {
                IsWorking = true;
                CurrentLEDString = string.Format("{0}  {1} {2} KG", CurrentJobNo.ForgingNO, CurrentJobNo.PRODU_NAME, CurrentIcmo.ProcessWeight.ToString("0"));
            }
            CurrentParameter = Const.IGDataDbContext.dy_plc_parameter.Where(id => id.CreateDate == (Const.IGDataDbContext.dy_plc_parameter.Max(tt => tt.CreateDate))).FirstOrDefault();
            CurrentForgeNo = CurrentJobNo.ForgingNO;
            var dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
            //CurrentWorkRecord =DataBase.V_WorkRecord.Where(p => p.CreateDate >= dt).OrderBy(p=>p.BeginTime).ToList();
            //CurrentWorkRecord = IGData.Database.SqlQuery<V_WorkRecord>(string.Format("SELECT * FROM V_WorkRecord WHERE EndTime>='{0}' ORDER BY BeginTime", dt)).ToList();
            */
        }

        /*
        public void QueryRealTimeData()
        {
            while (true)
            {
                DataMessagePublish.OnMessageEvent("后台检测运行正常！", Common.CommonClass.MessagePublisher.MessageType.Info);
                try
                {
                    if (MESData.task_view.Count() > 0)
                    {
                        DataMessagePublish.OnMessageEvent("检测到数据！", Common.CommonClass.MessagePublisher.MessageType.Debug);
                        if ((RealTimeHandler != null) && (!isRealQuery))
                        {
                            RealTimeHandler(this, null);
                        }

                    }
                    Thread.Sleep(Properties.Settings.Default.RealTimeInterval);
                    //Thread.Sleep(300000);
                }
                catch (System.Data.EntityException ee)
                {
                    //DataMessagePublish.OnMessageEvent("发送后台数据读取错误！", Common.CommonClass.MessagePublisher.MessageType.Debug);
                    ComFun.AppLog.WriteInfoLog(string.Format("Class: {0} Error{1}", ee.GetType().FullName, ee.Message.ToString()));
                }
                catch (Exception ex)
                {
                    //DataMessagePublish.OnMessageEvent("发送未知错误！", Common.CommonClass.MessagePublisher.MessageType.Debug);
                    ComFun.AppLog.WriteInfoLog(string.Format("Class: {0} Error{1}", ex.GetType().FullName, ex.Message.ToString()));
                }



            }

        }

        public void OnRealTimeEvent(object sender, EventArgs e)
        {
            AnalysisRealTimeData();
        }
       

        private void AnalysisRealTimeData()
        {
            isRealQuery = true;
            IsChanged = false;
            try
            {
                this.CurrentTaskView = MESData.task_view;
                foreach (var item in CurrentTaskView)
                {
                    decimal pw = 0.000M;
                    var kgs = MESData.uex_vtrack_record.Where(p => p.DISPATCH_CODE == item.DISPATCH_CODE && p.IS_DELETE == 0
                    && p.WORK_CENTER_GID ==Const.Config.ForgingEquipmentID);
                    if (kgs.Count() == 0)
                    {
                        var s = "未找到可用派工单信息，请及时联系管理员！";
                       
                        continue;
                    }
                    var ret = IGData.dy_plan_icmo.Find(kgs.First().ORDER_GID);
                    if (ret == null)
                    {
                        var dr = new DataBase.QID_IGDATA_ZY.dy_plan_icmo();
                        dr.Icmo_id = kgs.First().ORDER_GID;
                        //dr.BillNo = kgs.First().UDA3;
                        dr.BillNo = item.making_code;
                        dr.Name = kgs.First().PRODU_NAME;
                        dr.Code = kgs.First().PRODU_CODE;
                        var d = MESData.umpp_plan_order.Find(kgs.First().ORDER_GID);
                        if (d != null)
                        {
                            dr.Specification = d.UDA5;
                            dr.QTY = (short)d.QTY;
                            dr.OrderWeight = Math.Round(Convert.ToDecimal(d.UDA4), 2);
                            dr.ProcessWeight = Math.Round(Convert.ToDecimal(d.UDA4C), 2);
                            pw = dr.ProcessWeight;
                        }
                        dr.State = 0;
                        dr.IsDelete = 0;
                        dr.CombineMethod = Convert.ToByte(MESData.mbf_route_line.Find(kgs.First().ROUTE_GID).UDA12);
                        IGData.dy_plan_icmo.Add(dr);
                        DataSave(SaveDataType.dy);
                    }

                    //工艺路线关联                   
                    var retgy = IGData.dy_route_line.Find(kgs.First().ROUTE_GID);
                    if (retgy == null)
                    {
                        var dr = new DataBase.QID_IGDATA_ZY.dy_route_line();
                        dr.Route_id = kgs.First().ROUTE_GID;
                        var gyx = MESData.mbf_route_line.Find(kgs.First().ROUTE_GID);
                        dr.RouteName = gyx.NAME;
                        dr.RouteCode = gyx.CODE;
                        dr.ForgeNo = gyx.UDA1;
                        dr.ProcessWeight = pw; //工艺重量
                        dr.State = 0;
                        dr.IsDelete = 0;
                        dr.CombineMethod = Convert.ToByte(MESData.mbf_route_line.Find(kgs.First().ROUTE_GID).UDA12);
                        IGData.dy_route_line.Add(dr);
                        DataSave(SaveDataType.dy);
                    }
                }

            }

            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
                
                throw;
            }
            isRealQuery = false;
        }
        */
        /*
        /// <summary>
        /// 根据前台数据选择的变化，变更对应数据。
        /// </summary>
        /// <param name="Key">锻件编号</param>
        public void DataSelected(string Key)
        {
            var tv = Const.ZH_IMESDbContext.task_view.Where(d => d.mrl_code == Key);
            if (tv.Count() == 0) return;
            var c = tv.First().DISPATCH_CODE;
            var dr = Const.ZH_IMESDbContext.uex_vtrack_record.Where(d => d.DISPATCH_CODE == c && d.IS_DELETE == 0);
            if (dr.Count() == 0) return;
            var gid = dr.FirstOrDefault().GID;
            var r = Const.ZH_IMESDbContext.uex_vtrack_record.Find(gid);

            CurrentTask_View = Const.ZH_IMESDbContext.v_JRL_DY1.First<DataBase.ZH_IMES.v_JRL_DY1>();
            CurrentIcmo = Const.IGDataDbContext.dy_plan_icmo.Find(r.ORDER_GID);
            CurrentRoute = Const.IGDataDbContext.dy_route_line.Find(r.ROUTE_GID);
            CurrentJobNo = dr.FirstOrDefault();
            if (CurrentJobNo == null)
            {
                IsWorking = false;
            }
            else
            {
                IsWorking = true;
                CurrentLEDString = string.Format("{0}  {1} {2} KG", Key, CurrentJobNo.PRODU_NAME, CurrentIcmo.ProcessWeight.ToString("0"));
            }

            CurrentForgeNo = Key;
            var dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
            //CurrentWorkRecord =DataBase.V_WorkRecord.Where(p => p.CreateDate >= dt).OrderBy(p=>p.BeginTime).ToList();
            //CurrentWorkRecord = IGData.Database.SqlQuery<V_WorkRecord>(string.Format("SELECT * FROM V_WorkRecord WHERE EndTime>='{0}' ORDER BY BeginTime", dt)).ToList();

        }
        */


        /// <summary>
        /// 记录每次锻件锻压的记录。
        /// </summary>
        /// <param name="TemperatureValue">温度值</param>
        /// <param name="WorkpieceHeight">工件高度</param>
        public void WorkForging(WorkingPiece workpiece)
        {
            decimal pw = 0.000M;
            var ret = Const.IGDataDbContext.dy_plan_icmo.Find(workpiece.ORDER_GID);
            if (ret == null)
            {
                var dr = new DataBase.QID_IGDATA_ZY.dy_plan_icmo();
                dr.Icmo_id = workpiece.ORDER_GID;
                //dr.BillNo = kgs.First().UDA3;
                dr.BillNo = workpiece.ForgingNO;
                dr.Name = workpiece.PRODU_NAME;
                dr.Code = workpiece.PRODU_CODE;

                dr.Specification = workpiece.PRODU_SIZE;
                dr.QTY = (short)workpiece.PLAN_QTY;
                dr.OrderWeight = Math.Round(Convert.ToDecimal(workpiece.ORDER_WEIGHT), 2);
                dr.ProcessWeight = Math.Round(Convert.ToDecimal(workpiece.PROCESS_WEIGHT), 2);
                pw = dr.ProcessWeight;

                dr.State = 0;
                dr.IsDelete = 0;
                dr.CombineMethod = Convert.ToByte(workpiece.PORCESS_COMBINE);
                Const.IGDataDbContext.dy_plan_icmo.Add(dr);
                DataSave(SaveDataType.dy);
            }

            //工艺路线关联                   
            var retgy = Const.IGDataDbContext.dy_route_line.Find(workpiece.ROUTE_GID);
            if (retgy == null)
            {
                var dr = new DataBase.QID_IGDATA_ZY.dy_route_line();
                dr.Route_id = workpiece.ROUTE_GID;
                var gyx = Const.ZH_IMESDbContext.mbf_route_line.Find(workpiece.ROUTE_GID);
                dr.RouteName = gyx.NAME;
                dr.RouteCode = gyx.CODE;
                dr.ForgeNo = gyx.UDA1;
                dr.ProcessWeight = pw; //工艺重量
                dr.State = 0;
                dr.IsDelete = 0;
                dr.CombineMethod = Convert.ToByte(Const.ZH_IMESDbContext.mbf_route_line.Find(workpiece.ROUTE_GID).UDA12);
                Const.IGDataDbContext.dy_route_line.Add(dr);
                DataSave(SaveDataType.dy);
            }

            string[] forgings = Const.Config.ForgingWorkCells.ToArray();
            CurrentJobNo = Const.v_ForgingOperateDatas.Find(l => l.ForgingNO == workpiece.ForgingNO && forgings.Contains(l.WORKCELL_CODE));
            if (CurrentJobNo == null || (Const.v_ForgingOperateDatas.Count() == 0))
            {
                //DataMessagePublish.OnMessageEvent("未检测到派工单数据！", Common.CommonClass.MessagePublisher.MessageType.Info);
                //ComFun.AppLog.WriteInfoLog("未检测到派工单数据！");
                Const.Front.Notification = "未检测到派工单数据！";
                return;
            }
            var wr = Const.IGDataDbContext.dy_workrecord.Find(CurrentJobNo.GID);
            if (wr == null)
            {
                wr = new DataBase.QID_IGDATA_ZY.dy_workrecord();
                wr.WorkRecord_id = CurrentJobNo.GID;
                wr.ForgeNo = CurrentJobNo.ForgingNO;
                wr.ForgeName = CurrentJobNo.PRODU_NAME;
                wr.JobNo = CurrentJobNo.DISPATCH_CODE;
                wr.Icmo_id = CurrentJobNo.ORDER_GID;
                wr.Route_id = CurrentJobNo.ROUTE_GID;
                //wr.WorkCellNo = Const.ZH_IMESDbContext.pmbf_work_cell.Find(CurrentJobNo.WORK_CELL_GID).CODE;
                wr.WorkCellNo = workpiece.WORKCELL_CODE;
                //wr.CombineMethod = Convert.ToByte(Const.ZH_IMESDbContext.mbf_route_line.Find(CurrentJobNo.ROUTE_GID).UDA12);
                wr.CombineMethod = Convert.ToByte(workpiece.PORCESS_COMBINE);
                wr.CreateDate = DateTime.Now;
                wr.RecordType = 0;
                wr.State = 0;
                wr.IsDelete = 0;
                Const.IGDataDbContext.dy_workrecord.Add(wr);

                var rdd = new DataBase.QID_IGDATA_ZY.dy_workrecord_detail();
                rdd.WorkRecord_id = wr.WorkRecord_id;
                rdd.WorkRecordDetail_id = Const.CreateGID();
                rdd.SequenceNo = 1;
                if (CurrentParameter == null)
                {
                    rdd.Parameter_id = Const.IGDataDbContext.dy_plc_parameter.Where(p => p.CreateDate == Const.IGDataDbContext.dy_plc_parameter.Max(p2 => p2.CreateDate)).First().Parameter_id;
                    CurrentParameter = Const.IGDataDbContext.dy_plc_parameter.Find(rdd.Parameter_id);
                }
                else { rdd.Parameter_id = CurrentParameter.Parameter_id; }

                rdd.HeatCount = Convert.ToByte(CurrentJobNo.HEAT_COUNT);
                rdd.WorkpieceHeight = workpiece.WorkpieceHeight;
                rdd.TemperatureValue = workpiece.OutFurnaceTemperatures;
                rdd.WorkpieceTime = DateTime.Now;
                rdd.State = 0;
                rdd.IsDelete = 0;
                Const.IGDataDbContext.dy_workrecord_detail.Add(rdd);

                CurrentWorkRecord_id = wr.WorkRecord_id;
                CurrentWorkRecordDetail_id = rdd.WorkRecordDetail_id;
                CurrrentWorkrecordDetail = rdd;
            }
            else
            {
                int seq = Const.IGDataDbContext.dy_workrecord_detail.Where(r => r.WorkRecord_id == wr.WorkRecord_id).Count();
                var rdd = new DataBase.QID_IGDATA_ZY.dy_workrecord_detail();
                rdd.WorkRecord_id = CurrentJobNo.GID;
                rdd.WorkRecordDetail_id = Const.CreateGID();
                CurrentSeq = Const.IGDataDbContext.dy_workrecord_detail.Where(r => r.WorkRecord_id == rdd.WorkRecord_id).Count();
                rdd.SequenceNo = ++seq;
                if (CurrentParameter == null)
                {
                    rdd.Parameter_id = Const.IGDataDbContext.dy_plc_parameter.Where(p => p.CreateDate == Const.IGDataDbContext.dy_plc_parameter.Max(i2 => i2.CreateDate)).First().Parameter_id;
                }
                else { rdd.Parameter_id = CurrentParameter.Parameter_id; }
                rdd.HeatCount = Convert.ToByte(workpiece.HEAT_COUNT);
                rdd.WorkpieceHeight = workpiece.WorkpieceHeight;
                rdd.TemperatureValue = workpiece.OutFurnaceTemperatures;
                rdd.WorkpieceTime = DateTime.Now;
                rdd.State = 0;
                rdd.IsDelete = 0;
                Const.IGDataDbContext.dy_workrecord_detail.Add(rdd);

                CurrentWorkRecordDetail_id = rdd.WorkRecordDetail_id;
                CurrrentWorkrecordDetail = rdd;
            }

            Console.WriteLine(string.Format("更新了 {0} 锻压记录", DataSave(SaveDataType.dy)));
            //更新锻压接口表
            // UpdateQIDRecord(CurrentJobNo.DISPATCH_CODE);
            //var dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
            //Const.v_WorkRecords = Const.v_WorkRecords.Where(p => p.CreateDate >= dt).OrderBy(p => p.BeginTime).ToList();
            //CurrentWorkRecord = DataBase.Database.SqlQuery<V_WorkRecord>(string.Format("SELECT * FROM V_WorkRecord WHERE EndTime>='{0}' ORDER BY BeginTime", dt)).ToList();

        }


        public void SaveParameter(int baseValue, int fixValue, int currentValue)
        {
            var dr = new DataBase.QID_IGDATA_ZY.dy_plc_parameter();
            dr.BaseValue = baseValue;
            dr.WorktableHeight = fixValue;
            dr.SettingHeight = currentValue;
            dr.CreateDate = DateTime.Now;
            dr.IsDelete = 0;
            dr.State = 0;
            dr.Parameter_id = Const.CreateGID();
            Const.IGDataDbContext.dy_plc_parameter.Add(dr);

            DataSave(SaveDataType.dy);
            CurrentParameter = dr;
        }

        /*
        public void DataMain()
        {
            if (RealTimeQuery == null)
            {
                RealTimeQuery = new Thread(QueryRealTimeData);
                RealTimeHandler += OnRealTimeEvent;
                RealTimeQuery.IsBackground = true;
            }

            if (RealTimeQuery.IsAlive == false)
            {
                RealTimeQuery.Start();
            }

        }

        public void DataClosed()
        {
            if (RealTimeHandler != null)
            {
                RealTimeHandler -= OnRealTimeEvent;
            }
            if (RealTimeQuery.IsAlive)
            {
                RealTimeQuery.Abort();
                RealTimeQuery = null;
            }
        }
        */
        public int DataSave(SaveDataType dataType)
        {
            int isaved = 0;
            try
            {
                //DataMessagePublish.OnMessageEvent(string.Format("检索到 {0} 条数据更新！", isaved), Common.CommonClass.MessagePublisher.MessageType.Debug, isaved);
                //return isaved;
                if (SaveDataType.dy == dataType)
                {
                    isaved = Const.IGDataDbContext.SaveChanges();
                    if (isaved > 0) IsChanged = true;
                }
                if (SaveDataType.zh == dataType)
                {
                    isaved = Const.ZH_IMESDbContext.SaveChanges();
                    if (isaved > 0) IsChanged = true;
                }
                if (SaveDataType.mes == dataType)
                {
                    isaved = Const.IGDataDbContext.SaveChanges();
                    if (isaved > 0) IsChanged = true;
                }
                if (IsChanged)
                {
                    //DataMessagePublish.OnMessageEvent(string.Format("检索到 {0} 条数据更新！", isaved), Common.CommonClass.MessagePublisher.MessageType.Debug, isaved);
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Console.WriteLine(string.Format("Class: {0}, Property: {1}, Error: {2}", validationErrors.Entry.Entity.GetType().FullName,
                            validationError.PropertyName,
                            validationError.ErrorMessage));
                        //ComFun.AppLog.WriteErrorLog(string.Format("Class: {0}, Property: {1}, Error: {2}", validationErrors.Entry.Entity.GetType().FullName, validationError.PropertyName, validationError.ErrorMessage));
                    }
                }
                throw;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message.ToString());
                //ComFun.AppLog.WriteErrorLog(string.Format("Class: {0}, Error: {1}", ex.GetType().FullName, ex.Message.ToString()));
                throw;
            }

            return isaved;
        }

        private string changeConString(string uid, string pwd, string conallstr)
        {
            var sqlbud = new System.Data.SqlClient.SqlConnectionStringBuilder();
            sqlbud.ConnectionString = conallstr;
            sqlbud.UserID = uid;
            sqlbud.Password = pwd;
            return sqlbud.ConnectionString;
        }

        /*private void UpdatDBConString()
        {
            var password = Properties.Settings.Default.DBPassWord;
            var AES = new Common.AESCryptHelper();
            AES.ContainKey = true;
            var ups = AES.Decrypt(password).Split(';');
            if (ups.Length < 3)
            {
                var s = "后台数据连接问题，请及时联系管理员！";
                DataMessagePublish.OnMessageEvent(s, Common.CommonClass.MessagePublisher.MessageType.Info);
                ComFun.AppLog.WriteInfoLog(s);
                return;
            }
            var up = ups[0].Split(',');
            IGData.Database.Connection.ConnectionString = changeConString(up[0], up[1], IGData.Database.Connection.ConnectionString);
            up = ups[1].Split(',');
            MESData.Database.Connection.ConnectionString = changeConString(up[0], up[1], MESData.Database.Connection.ConnectionString);
            up = ups[2].Split(',');
            IGData.Database.Connection.ConnectionString = changeConString(up[0], up[1], IGData.Database.Connection.ConnectionString);

        }
        */


        #region 新增方法

        public List<DataBase.ZH_IMES.V_ForgingOperateData> GetV_ForgingOperateData()
        {
            string[] wc = Const.Config.WorkCells.ToArray<string>();
            var OperateData = Const.ZH_IMESDbContext.V_ForgingOperateData.Where(v => v.WORK_CENTER_GID == Const.Config.WorkCenter && v.DIS_CODE_STATE != 3 && wc.Contains(v.WORKCELL_CODE)).ToList<DataBase.ZH_IMES.V_ForgingOperateData>();
            return OperateData;
        }

        public List<DataBase.ZH_IMES.V_ForgingOperateData> GetInFurnaceData()
        {
            ;
            InFurnaceData = GetV_ForgingOperateData().Where(d => d.InFurnace == "1").ToList<DataBase.ZH_IMES.V_ForgingOperateData>();
            return InFurnaceData;
        }

        public List<DataBase.ZH_IMES.V_ForgingOperateData> GetOutFurnaceData()
        {
            OutFurnaceData = GetV_ForgingOperateData().Where(d => d.InFurnace == "0").ToList<DataBase.ZH_IMES.V_ForgingOperateData>();
            return OutFurnaceData;
        }

        #endregion

    }

}



